package com.wwf;

import com.wwf.util.RpcRequest;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;

import java.util.concurrent.Callable;

/**
 * @author lulei
 * @date 2021年01月07日 14:29:11
 */
public class UserClientHandler extends ChannelInboundHandlerAdapter implements Callable {
    private ChannelHandlerContext ctx;

    public void setResult(String result) {
        this.result = result;
    }

    private String result;
    private RpcRequest para;
    @Override
    public synchronized Object call() throws Exception {
        System.out.println("call 方法调用了");
        if(ctx != null)
            ctx.writeAndFlush(para);
        wait(1000);
        return result;
    }

    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {
        this.ctx = ctx;
    }

    @Override
    public synchronized void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        result=  msg.toString();//读取服务端的返回值
        notify();//唤起call
    }
    public void setPara(RpcRequest para){
        this.para = para;
    }
}
